package com.ruoyi.web.controller.map;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.MapCompositeIndex;
import com.ruoyi.system.service.IMapCompositeIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 城市发展综合指数Controller
 *
 * @author cqust_icc
 * @date 2022-06-23
 */
@RestController
@RequestMapping("/system/CompositeIndex")
public class MapCompositeIndexController extends BaseController
{
    @Autowired
    private IMapCompositeIndexService mapCompositeIndexService;

    /**
     * 查询城市发展综合指数列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MapCompositeIndex mapCompositeIndex)
    {
        startPage();
        List<MapCompositeIndex> list = mapCompositeIndexService.selectMapCompositeIndexList(mapCompositeIndex);
        return getDataTable(list);
    }

    /**
     * 导出城市发展综合指数列表
     */
    @PreAuthorize("@ss.hasPermi('system:CompositeIndex:export')")
    @Log(title = "城市发展综合指数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MapCompositeIndex mapCompositeIndex)
    {
        List<MapCompositeIndex> list = mapCompositeIndexService.selectMapCompositeIndexList(mapCompositeIndex);
        ExcelUtil<MapCompositeIndex> util = new ExcelUtil<MapCompositeIndex>(MapCompositeIndex.class);
        util.exportExcel(response, list, "城市发展综合指数数据");
    }

    /**
     * 获取城市发展综合指数详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:CompositeIndex:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mapCompositeIndexService.selectMapCompositeIndexById(id));
    }

    /**
     * 新增城市发展综合指数
     */
    @PreAuthorize("@ss.hasPermi('system:CompositeIndex:add')")
    @Log(title = "城市发展综合指数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MapCompositeIndex mapCompositeIndex)
    {
        return toAjax(mapCompositeIndexService.insertMapCompositeIndex(mapCompositeIndex));
    }

    /**
     * 修改城市发展综合指数
     */
    @PreAuthorize("@ss.hasPermi('system:CompositeIndex:edit')")
    @Log(title = "城市发展综合指数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MapCompositeIndex mapCompositeIndex)
    {
        return toAjax(mapCompositeIndexService.updateMapCompositeIndex(mapCompositeIndex));
    }

    /**
     * 删除城市发展综合指数
     */
    @PreAuthorize("@ss.hasPermi('system:CompositeIndex:remove')")
    @Log(title = "城市发展综合指数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mapCompositeIndexService.deleteMapCompositeIndexByIds(ids));
    }

    @Log(title = "发展综合指数批量导入", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:CompositeIndex:add')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<MapCompositeIndex> util = new ExcelUtil<>(MapCompositeIndex.class);
        List<MapCompositeIndex> baseList = util.importExcel("区县首页六边形",file.getInputStream(),0);
        String message = mapCompositeIndexService.importData(baseList);
        return AjaxResult.success(message);
    }
}
